com.github.droidfu.http
Class BetterHttp

java.lang.Object
  extended by com.github.droidfu.http.BetterHttp

public class BetterHttp
extends Object


Field Summary
static String DEFAULT_HTTP_USER_AGENT
           
static int DEFAULT_MAX_CONNECTIONS
           
static int DEFAULT_SOCKET_TIMEOUT
           
 
Constructor Summary
BetterHttp()
           
 
Method Summary
static BetterHttpRequest delete(String url)
           
static void enableGZIPEncoding()
          Intercept requests to have them ask for GZip encoding and intercept responses to automatically wrap the response entity for reinflation.
static void enableResponseCache(android.content.Context context, int initialCapacity, long expirationInMinutes, int maxConcurrentThreads, int diskCacheStorageDevice)
          Enables caching of HTTP responses.
static void enableResponseCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads)
          Enables caching of HTTP responses.
static BetterHttpRequest get(String url)
           
static BetterHttpRequest get(String url, boolean cached)
           
static HashMap<String,String> getDefaultHeaders()
           
static org.apache.http.impl.client.AbstractHttpClient getHttpClient()
           
static HttpResponseCache getResponseCache()
           
static int getSocketTimeout()
           
static BetterHttpRequest post(String url)
           
static BetterHttpRequest post(String url, org.apache.http.HttpEntity payload)
           
static BetterHttpRequest put(String url)
           
static BetterHttpRequest put(String url, org.apache.http.HttpEntity payload)
           
static void setContext(android.content.Context context)
           
static void setDefaultHeader(String header, String value)
           
static void setHttpClient(org.apache.http.impl.client.AbstractHttpClient httpClient)
           
static void setMaximumConnections(int maxConnections)
           
static void setPortForScheme(String scheme, int port)
           
static void setSocketTimeout(int socketTimeout)
          Adjust the socket timeout, i.e.
static void setupHttpClient()
           
static void setUserAgent(String userAgent)
           
static void updateProxySettings()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_CONNECTIONS

public static final int DEFAULT_MAX_CONNECTIONS
See Also:
Constant Field Values

DEFAULT_SOCKET_TIMEOUT

public static final int DEFAULT_SOCKET_TIMEOUT
See Also:
Constant Field Values

DEFAULT_HTTP_USER_AGENT

public static final String DEFAULT_HTTP_USER_AGENT
See Also:
Constant Field Values
Constructor Detail

BetterHttp

public BetterHttp()
Method Detail

setupHttpClient

public static void setupHttpClient()

enableResponseCache

public static void enableResponseCache(int initialCapacity,
                                       long expirationInMinutes,
                                       int maxConcurrentThreads)
Enables caching of HTTP responses. This will only enable the in-memory cache. If you also want to enable the disk cache, see enableResponseCache(Context, int, long, int, int) .

Parameters:
initialCapacity - the initial element size of the cache
expirationInMinutes - time in minutes after which elements will be purged from the cache
maxConcurrentThreads - how many threads you think may at once access the cache; this need not be an exact number, but it helps in fragmenting the cache properly
See Also:
HttpResponseCache

enableGZIPEncoding

public static void enableGZIPEncoding()
Intercept requests to have them ask for GZip encoding and intercept responses to automatically wrap the response entity for reinflation. This code is based on code from SyncService in the Google I/O 2010 scheduling app.


enableResponseCache

public static void enableResponseCache(android.content.Context context,
                                       int initialCapacity,
                                       long expirationInMinutes,
                                       int maxConcurrentThreads,
                                       int diskCacheStorageDevice)
Enables caching of HTTP responses. This will also enable the disk cache.

Parameters:
context - the current context
initialCapacity - the initial element size of the cache
expirationInMinutes - time in minutes after which elements will be purged from the cache (NOTE: this only affects the memory cache, the disk cache does currently NOT handle element TTLs!)
maxConcurrentThreads - how many threads you think may at once access the cache; this need not be an exact number, but it helps in fragmenting the cache properly
diskCacheStorageDevice - where files should be cached persistently ( AbstractCache.DISK_CACHE_INTERNAL, AbstractCache.DISK_CACHE_SDCARD )
See Also:
HttpResponseCache

getResponseCache

public static HttpResponseCache getResponseCache()
Returns:
the response cache, if enabled, otherwise null

setHttpClient

public static void setHttpClient(org.apache.http.impl.client.AbstractHttpClient httpClient)

getHttpClient

public static org.apache.http.impl.client.AbstractHttpClient getHttpClient()

updateProxySettings

public static void updateProxySettings()

get

public static BetterHttpRequest get(String url)

get

public static BetterHttpRequest get(String url,
                                    boolean cached)

post

public static BetterHttpRequest post(String url)

post

public static BetterHttpRequest post(String url,
                                     org.apache.http.HttpEntity payload)

put

public static BetterHttpRequest put(String url)

put

public static BetterHttpRequest put(String url,
                                    org.apache.http.HttpEntity payload)

delete

public static BetterHttpRequest delete(String url)

setMaximumConnections

public static void setMaximumConnections(int maxConnections)

setSocketTimeout

public static void setSocketTimeout(int socketTimeout)
Adjust the socket timeout, i.e. the amount of time that may pass when waiting for a server response. Time unit is milliseconds.

Parameters:
socketTimeout - the timeout in milliseconds

getSocketTimeout

public static int getSocketTimeout()

setDefaultHeader

public static void setDefaultHeader(String header,
                                    String value)

getDefaultHeaders

public static HashMap<String,String> getDefaultHeaders()

setContext

public static void setContext(android.content.Context context)

setPortForScheme

public static void setPortForScheme(String scheme,
                                    int port)

setUserAgent

public static void setUserAgent(String userAgent)


Copyright © 2011. All Rights Reserved.